import gov.nih.mipav.model.structures.VOI;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 * This class contains all the information related to the region itself. The voi
 * added to the images, the name, its media, variance and curtosis.
 * 
 * @author ubuntu
 */
public class Region {

  private ArrayList<VOI> VOIs;
  private String name;
  private double media;
  private double variance;
  private double curtosis;

  public Region(String name) {
    this.name = name;
    VOIs = new ArrayList<VOI>();
  }

  public void addVOI(VOI voi) {
    VOIs.add(voi);
  }

  // returns the image where it was
  public void removeVOI(VOI voi) {
    String name = null;
    if (VOIs.contains(voi)) {
      VOIs.remove(voi);
    }
  }

  public boolean isVOIinRegion(VOI voi) {
    return VOIs.contains(voi);
  }

  public boolean inRegion(int x, int y, int z) {

    boolean ret = false;

    for (Iterator<VOI> iterator = VOIs.iterator(); iterator.hasNext();) {
      VOI voi = (VOI) iterator.next();

      float distance = voi.pointToContour(x, y, z);
      if (distance < 0.0)
        ret = true;

    }

    return ret;
  }

  public Collection<VOI> getVOIs() {
    return VOIs;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    for (Iterator<VOI> iterator = VOIs.iterator(); iterator.hasNext();) {
      VOI voi = (VOI) iterator.next();
      voi.setName(name);
    }
    this.name = name;
  }

  public String toString() {
    return this.name;
  }

  public void setMedia(double media) {
    this.media = media;
  }

  public void setVariance(double variance) {
    this.variance = variance;
  }

  public double getMedia() {
    return media;
  }

  public double getVariance() {
    return variance;
  }

  public void setCurtosis(double curtosis) {
    this.curtosis = curtosis;
  }

  public double getCurtosis() {
    return this.curtosis;
  }

  @Override
  public boolean equals(Object object) {
    return (object instanceof Region)
        && this.name.equals(((Region) object).getName());
  }

}
